package io.github.shang11925.sbvuewelearn.service.impl;

import io.github.shang11925.sbvuewelearn.dao.SectionsRepository;
import io.github.shang11925.sbvuewelearn.dto.SectionsDTO;
import io.github.shang11925.sbvuewelearn.entity.Sections;
import io.github.shang11925.sbvuewelearn.service.SectionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SectionsServiceImpl implements SectionsService {
    @Autowired
    SectionsRepository SectionsRepository;
    @Autowired
    private SectionsRepository sectionsRepository;


    @Override
    public List<Sections> findAll() {
        return SectionsRepository.findAll();
    }

    @Override
    public List<Sections> findByChapterId(Long chapterId) {
        return sectionsRepository.findByChapterId(chapterId);
    }

    @Override
    public void add(SectionsDTO sectionsDTO) {
        Sections sections = new Sections();
        sections.setTitle(sectionsDTO.getTitle());
        sections.setType(sectionsDTO.getType());
        sections.setChapterId(sectionsDTO.getChapter_id());

        sectionsRepository.save(sections);
    }
    @Override
    public void delete(Long id) {
        sectionsRepository.deleteById(id);

    }
}
